package server.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionMyDataBase {
    public static Connection dbConnection = null;

    public static void makeConnection() throws SQLException {
        String dbName = "MyDatabase";
        String database = "jdbc:sqlite:" + dbName;
        //如果数据库不存在，那么它就会被创建，最后将返回一个数据库对象
        dbConnection = DriverManager.getConnection(database);
        System.out.println("Connection to SQLite has been established.");
    }
    public void closeDB() throws SQLException {
        if (null != dbConnection) {
            dbConnection.close();
            System.out.println("closing db connection");
            dbConnection = null;
        }
    }
}
